package jfxtras.scene.control;


import java.math.BigInteger;


/**
 * A base class that provides default behavior
 * 
 * @author Tom Eugelink
 *
 */
public class SpinnerXDataProviderAbstract
{
	/**
	 * 
	 * @param min
	 * @param max
	 */
	public SpinnerXDataProviderAbstract(int min, int max)
	{
		this.min = min;
		this.max = max;
	}
	private int min;
	private int max;
	
	/**
	 * 
	 * @param idx
	 * @return
	 */
	public BigInteger getPreviousIdx(BigInteger idx)
	{
		// null means "positive endless", so return maximum index
		if (idx == null) return BigInteger.valueOf(max);
		
		// decrement				
		BigInteger lIdx = idx.subtract(BigInteger.ONE);
		if (lIdx.intValue() < min) return null; // no previous index
		return lIdx;
	}

	/**
	 * 
	 * @param idx
	 * @return
	 */
	public BigInteger getNextIdx(BigInteger idx)
	{
		// null means "negative endless", so return minimum index
		if (idx == null) return BigInteger.valueOf(min);
		
		// increment
		BigInteger lIdx = idx.add(BigInteger.ONE);
		if (lIdx.intValue() > max) return null; // no next index
		return lIdx;
	}
}
